
mean.by.state <- function(x,state,wt=NULL){
	out <- rep(NA,length(state.abb))
	if (is.null(wt)){wt <- rep(1,length(x))}
	for (st in state.abb) {
		out[match(st,state.abb)] <- sum(x[state==st]*wt[state==st],na.rm=TRUE)/sum(wt[state==st],na.rm=TRUE)
	}
	return (out)
}

cum.sum <- function(x) {
	y <- rep(NA,length(x))
	y[1] <- x[1]
	for (i in 2:length(x)) y[i] <- y[i-1]+x[i]
	return(y)
}
